package com.content_module.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.content_module.R;
import com.content_module.R2;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import component.fy.com.common_module.base.BaseActivity;
import component.fy.com.common_module.utils.ToastUtil;
import component.fy.com.common_module.view.FlowLayout.FlowLayout;
import component.fy.com.common_module.view.FlowLayout.TagAdapter;
import component.fy.com.common_module.view.FlowLayout.TagFlowLayout;

public class TagFlowLayoutAct extends BaseActivity {
    @BindView(R2.id.content_act_tag_flow_layout_tag)
    TagFlowLayout tagFlowLayout;

    private List<String> list = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.content_act_tag_flow_layout;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initEvents() {
        tagFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int tagPosition, FlowLayout parent) {
                ToastUtil.showToast("点击位置=" + tagPosition);
                return true;
            }
        });
    }

    @Override
    protected void initData() {
        list.add("返回主App");
        list.add("BaseRecyclerAdapter不同布局展示");
        list.add("TagFlowLayout");
        setTagData(list);
    }

    private void setTagData(final List<String> list) {
        tagFlowLayout.setAdapter(new TagAdapter(list) {
            @Override
            public View getView(FlowLayout parent, int tagPosition, Object o) {
                TextView tv = (TextView) LayoutInflater.from(TagFlowLayoutAct.this).inflate(R.layout.tag_tv_size, tagFlowLayout, false);
                tv.setText(list.get(tagPosition));
                setTagTextStyle(tv);
                return tv;
            }
        });
    }

    /**
     * 设置tag标签的字体样式
     *
     * @param textView
     */
    private void setTagTextStyle(TextView textView) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 0, 20, 20);
        textView.setLayoutParams(params);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        clearList(list);
    }
}
